// (c)2019 YanFriends Inc, All Rights Reserved.
package com.ysalliance.getFan.organization.ui.base;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.ysalliance.getFan.organization.Bean.UserBean;
import com.ysalliance.getFan.organization.R;
import com.ysalliance.getFan.organization.myview.ProgressBarHandler;

import org.litepal.LitePal;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import butterknife.ButterKnife;
import io.reactivex.disposables.Disposable;


// (c)2019 YanFriends Inc, All Rights Reserved.


/**
 * @author vondear
 */
public abstract class LucasBaseActivity extends AppCompatActivity {

    /** 日志输出标志 **/
    protected final String TAG = this.getClass().getSimpleName();
    /** 上下文context **/
    public LucasBaseActivity mContext;
    /** RXjava释放 **/
    protected Disposable disposable;
    /** 用户 **/
    public UserBean userBean;


    //耗时缓冲bar
    public ProgressBarHandler mProgressBarHandler;





    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        beforeView();
        setContentView(bindContentView());
        ButterKnife.bind(this);
        afterView();

    }


    public void beforeView() {
        if(LitePal.findFirst(UserBean.class)!=null){
            userBean = LitePal.findFirst(UserBean.class);
        }

    }

    /**   绑定view  */
    public abstract int bindContentView();

    public void afterView() {
        /**    隐藏actionbar  沉浸式状态栏   */
        ActionBar actionBar = getSupportActionBar();
        if(actionBar != null){
            actionBar.hide();
        }
        //融合状态栏
        if(Build.VERSION.SDK_INT >=21){
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            );
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        /**    更改状态栏为黑字体     */
        changeStatusBarTextColor(true);

        /**   缓冲bar  .show()  .hide() */
        mProgressBarHandler = new ProgressBarHandler(mContext); // In onCreate


        /**   返回键     */
        if(findViewById(R.id.img_back)!=null){
            findViewById(R.id.img_back).setOnClickListener(v->{onBackPressed();});
        }


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    protected void onResume() {
        super.onResume();





    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unsubscribe();



    }



    /** RXjava释放 **/
    protected void unsubscribe() {
        if (disposable != null && !disposable.isDisposed()) {
            disposable.dispose();
        }
    }



    public void changeStatusBarTextColor(boolean isBlack) {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (isBlack) {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//设置状态栏黑色字体
            }else {
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);//恢复状态栏白色字体
            }
        }
    }





}



